/*
 * PathContextTransferHandler.java
 *
 * Created on July 26, 2007, 1:11 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package dnbW.uiW.dbW;

import java.awt.datatransfer.Transferable;
import javax.swing.Icon;
import javax.swing.JComponent;
import javax.swing.JTree;
import javax.swing.TransferHandler;
import javax.swing.tree.TreePath;

/**
 * A transfer handler to create a transferable for drag-and-drop operation
 * @author zhouyong
 */
public class PathContextTransferHandler
        extends TransferHandler{
    
    /** Creates a new instance of PathContextTransferHandler */
    public PathContextTransferHandler() {
    }
    
    // disable data import
    @Override
    public boolean canImport(TransferHandler.TransferSupport support) {
        return false;
    }
    
    /**
     * Creates a Transferable to use as the source for a data transfer. 
     * Returns the representation of the data to be transferred, or null 
     * if the component's property is null
     * @param c
     * @return
     */
    @Override
    protected Transferable createTransferable(JComponent c) {
        if(c!= null && c instanceof JTree){
            JTree jt = (JTree)c;
            TreePath[] paths = jt.getSelectionPaths();
            
            if (paths != null) {
                PathContext context = new PathContext(paths[0]);
                return new PathContextTransferable(context);
            }
        }
        return null;
    }
    
    @Override
    public int getSourceActions(JComponent c) {
        return COPY_OR_MOVE;
    }

    @Override
    public Icon getVisualRepresentation(Transferable t) {
        System.out.println("getting the visual presentation.....");
        
        return null;
    }
    
}
